package com.wash.shoes.controller.pc;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.core.domain.R;
import com.wash.shoes.entity.ShopPo;
import com.wash.shoes.entity.UserShopPo;
import com.wash.shoes.exception.WashException;
import com.wash.shoes.service.UserShopService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author ljg
 * @since 2024-10-11
 */
@Api(tags = {"PC-用户关联的店铺"})
@RestController
@RequestMapping({"/userShop", "/dev-api/userShop"})
public class UserShopController {


    @Autowired
    UserShopService userShopService;

    @ApiOperation("没有关联的店铺")
    @GetMapping("/noConnectionShopList")
    public R<Page<ShopPo>> noConnectionShopList(String shopName, String userId,String type) {
        Page<ShopPo> page = userShopService.noConnectionShopList(shopName, userId,type);
        return R.ok(page);
    }


    @ApiOperation("用户关联的门店列表")
    @GetMapping("/userShopList")
    public R<Page<ShopPo>> userShopList(String userId) {
        Page<ShopPo> page = userShopService.userShopList(userId);
        return R.ok(page);
    }


    @ApiOperation("用户关联门店")
    @GetMapping("/userAssociateShop")
    public R<String> userShopList(String userId, String shopId) {

        UserShopPo userShopPo = userShopService.userAssociateShopData(userId, shopId);
        if (userShopPo != null) {
            throw new WashException("该门店已经关联");
        }

        userShopPo = new UserShopPo();
        userShopPo.setUserId(userId);
        userShopPo.setShopId(shopId);
        userShopService.save(userShopPo);

        return R.ok(userShopPo.getId());
    }


    @ApiOperation("用户取消关联门店")
    @GetMapping("/userCancelAssociateShop")
    public R<String> userCancelAssociateShop(String userId, String shopId) {

        UserShopPo userShopPo = userShopService.userAssociateShopData(userId, shopId);
        if (userShopPo != null) {
            userShopService.removeById(userShopPo);
        }
        return R.ok(userShopPo.getId());
    }


}

